package com.ascainiao
{
	import com.ascainiao.control.BaseControl;
	import com.ascainiao.control.LayerControl;
	import com.ascainiao.events.ControlEvent;
	
	import flash.events.EventDispatcher;

	/**
	 * @author 小飞侠
	 * @E-mail: 405076856@qq.com
	 * 创建时间：2021-12-7 下午4:01:14
	 *
	 * ASCaiNiao引擎
	 * 程序入口
	 */
	public class ASCaiNiao
	{
		//项目配置
		private var config:ProjectConfig;
		//分层管理
		private var layer:LayerControl;
		//消息分发
		private var message:EventDispatcher=new EventDispatcher();
		//模块
		private var _controls:Vector.<BaseControl>=new Vector.<BaseControl>();
		public function ASCaiNiao(c:ProjectConfig)
		{
			config=c;
			layer=new LayerControl(config);
			//
			for(var i:int=0;i<config.controls.length;i++){
				var ObjClass:Class=config.controls[i] as Class;
				var control:BaseControl=new ObjClass(layer,message) as BaseControl;
				_controls.push(control);
			}
		}
		public function send(e:*):void{
			if(e is String){
				message.dispatchEvent(new ControlEvent(e));
			}else{
				message.dispatchEvent(e);
			}
		}
		public function receive(name:String,callback:Function):void{
			message.addEventListener(name,callback);
		}
	}
}